{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#APPLY Histogram Equalization to V channel of HSV frame\n",
    "cv2.namedWindow('input')\n",
    "cv2.namedWindow('output')\n",
    "colors = np.zeros((3))\n",
    "\n",
    "\n",
    "\n",
    "out = np.zeros_like((vidsize))\n",
    "\n",
    "\n",
    "while cap.isOpened():\n",
    "    ret,image_np = cap.read()\n",
    "    if ret == True:\n",
    "        originalImage = image_np.copy()\n",
    "        \n",
    "        #Convert the RGB frame to HSV and seperate them\n",
    "        image_np = cv2.cvtColor(image_np,cv2.COLOR_BGR2HSV)\n",
    "        H = image_np[:,:,0]\n",
    "        S = image_np[:,:,1]\n",
    "        V = image_np[:,:,2]\n",
    "\n",
    "        V = cv2.equalizeHist(V) #apply histogram equalization to only V channel\n",
    "\n",
    "        \n",
    "        out = cv2.merge((H,S,V)) #combine H,S,V channels\n",
    "        out2 = cv2.cvtColor(out,cv2.COLOR_HSV2BGR) #convert to RGB\n",
    "        \n",
    "        \n",
    "        cv2.imshow('input', originalImage)\n",
    "        cv2.imshow('output', out2)\n",
    "        if cv2.waitKey(25) & 0xFF == ord('q'):\n",
    "            cv2.destroyAllWindows()\n",
    "            break\n",
    "    else:\n",
    "        break\n",
    " \n",
    "\n",
    "\n",
    "cap.release()               \n",
    "cv2.destroyAllWindows()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#RGB-Histogram Equalization\n",
    "cv2.namedWindow('input')\n",
    "cv2.namedWindow('output')\n",
    "colors = np.zeros((3))\n",
    "\n",
    "\n",
    "\n",
    "out = np.zeros_like((vidsize))\n",
    "out2 = np.zeros_like((vidsize))\n",
    "\n",
    "\n",
    "while cap.isOpened():\n",
    "    ret,image_np = cap.read()\n",
    "    if ret == True:\n",
    "        #seperate channels\n",
    "        red = image_np[:,:,2]\n",
    "        green = image_np[:,:,1]\n",
    "        blue = image_np[:,:,0]\n",
    "        \n",
    "        #Apply Histogram Equalization to each channel\n",
    "        blue=cv2.equalizeHist(blue)\n",
    "        green=cv2.equalizeHist(green)\n",
    "        red=cv2.equalizeHist(red)\n",
    "        \n",
    "\n",
    "        out = cv2.merge((blue,green,red)) #combine all channels\n",
    "        \n",
    "        \n",
    "        cv2.imshow('input', image_np)\n",
    "        cv2.imshow('output', out)\n",
    "        if cv2.waitKey(25) & 0xFF == ord('q'):\n",
    "            cv2.destroyAllWindows()\n",
    "            break\n",
    "    else:\n",
    "        break\n",
    " \n",
    "\n",
    "\n",
    "cap.release()               \n",
    "cv2.destroyAllWindows()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
